<template>
  <avue-crud
    :option="option"
    :table-loading="loading"
    :data="data"
    ref="crud"
    v-model="form"
    :permission="permissionList"
    :search.sync="search"
    @row-del="rowDel"
    :before-open="beforeOpen"
    :page="page"
    @search-change="searchChange"
    @search-reset="searchReset"
    @selection-change="selectionChange"
    @current-change="currentChange"
    @size-change="sizeChange"
    @refresh-change="refreshChange"
    @on-load="onLoad"
  >
    <template #menuLeft>
      <div class="flex-start">
        <el-date-picker
          size="small"
          v-model="searchDate"
          type="daterange"
          class="m-r-10"
          value-format="yyyy-MM-dd"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          @change="refreshChange"
        />
        <el-input
          placeholder="请输入推广员姓名"
          size="small"
          style="width: 250px"
          v-model="query.sharerName"
          @change="refreshChange"
          suffix-icon="el-icon-search"
        />
      </div>
    </template>
    <template #menuRight>
      <el-button type="primary" size="small">报表下载</el-button>
    </template>
  </avue-crud>
</template>

<script>
import { getList } from "@/api/marketing-management/marketing-statistics-promotion-filling";
import { mapGetters } from "vuex";

export default {
  data() {
    return {
      form: {},
      search: {},
      roleBox: false,
      excelBox: false,
      loading: true,
      selectionList: [],
      query: {},
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      props: {
        label: "title",
        value: "key",
      },
      option: {
        columnBtn: false,
        refreshBtn: false,
        height: "auto",
        calcHeight: 310,
        searchShow: true,
        searchMenuSpan: 6,
        tip: false,
        border: true,
        index: true,
        viewBtn: false,
        addBtn: false,
        menu: false,
        align: "center",
        column: [
          {
            label: "加注单号",
            prop: "recordCode",
            minWidth: 120,
            span: 24,
          },
          {
            label: "推广员姓名",
            prop: "sharerName",
            width: 120,
            span: 24,
          },
          {
            label: "加注金额（元）",
            prop: "moneyAmount",
            width: 130,
            span: 24,
          },
          {
            label: "加注量（kg）",
            prop: "actualWeight",
            width: 130,
            span: 24,
          },
          {
            label: "加注机编号",
            prop: "macCode",
            width: 130,
            span: 24,
          },
          {
            label: "加注站名称",
            prop: "siteName",
            span: 24,
          },
          {
            label: "加注时间",
            prop: "fillTime",
            type: "datetime",
            width: 160,
            format: "yyyy-MM-dd HH:mm:ss",
            span: 24,
          },
        ],
      },
      data: [],
      searchDate: "",
    };
  },
  computed: {
    ...mapGetters(["permission"]),
  },
  methods: {
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
    },
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
    },
    refreshChange() {
      console.log(this.searchDate);
      if (this.searchDate) {
        this.query.startDate = this.searchDate[0];
        this.query.endDate = this.searchDate[1];
      } else {
        this.query.startDate = "";
        this.query.endDate = "";
      }
      this.onLoad(this.page, this.query);
    },
    onLoad(page, params = {}) {
      this.loading = true;
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
      });
    },
  },
};
</script>

<style></style>
